package recharge_management

import (
	"context"

	"gitee.com/liuxuezhan/ar-platform/rpc-client/assetsClient/rpc"

	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type ThirdpartyBankInfoLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 代收三方银行--获取一条记录
func NewThirdpartyBankInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ThirdpartyBankInfoLogic {
	return &ThirdpartyBankInfoLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ThirdpartyBankInfoLogic) ThirdpartyBankInfo(req *types.ThirdpartyBankInfoRequest) (resp *types.ThirdpartyBankInfoResponse, err error) {
	rpcReq := rpc.ThirdpartyBankInfoRequest{
		Id: req.Id,
	}

	rpcResp, err := l.svcCtx.AssetsRpc.TenantChannel.ThirdpartyBankInfo(l.ctx, &rpcReq)
	// if err != nil {
	//	var code int32
	//	var message string
	//	if rpcResp != nil && rpcResp.CommonResp != nil {
	//		code = rpcResp.CommonResp.Code
	//		message = rpcResp.CommonResp.Message
	//	} else {
	//		code = xerrors.DBError
	//		message = "Database operation error."
	//	}
	//	return &types.ThirdpartyBankInfoResponse{
	//		CommonResp: types.CommonResp{
	//			Code:    code,
	//			Message: message,
	//		},
	//	}, nil
	// }
	if err != nil {
		return nil, err
	}

	return &types.ThirdpartyBankInfoResponse{
		Id:        rpcResp.Id,
		AgentName: rpcResp.AgentName,
		BankName:  rpcResp.BankName,
		BankCode:  rpcResp.BankCode,
		Sort:      rpcResp.Sort,
		Status:    rpcResp.Status,
		CommonResp: types.CommonResp{
			Message: "ok",
		},
	}, nil
}
